import {Injectable} from '@angular/core';
import { NzModalService } from 'ng-zorro-antd';
@Injectable({
  providedIn: 'root'
})
export class CommonService {

  constructor(private modalService: NzModalService) {}
  /**
   * 模态框
   * showConfirm 有确定按钮
   * title
   * msg
   * callback 回调
   */
  showConfirm(title , msg , callback ): any {
    this.modalService.confirm({
      nzTitle: `<i>${title}</i>`,
      nzContent: `<b>${msg}</b>`,
      nzOnOk: callback
    });
  }
  /**
   * 模态框
   * createModal 自定义弹窗
   * title
   * component 模版
   * callback 回调
   */
  createModal(title , component , callback ): any {
    this.modalService.create({
      nzTitle: title,
      nzContent: component,
      nzOkText: '保存',
      nzCancelText: '取消',
      nzMaskClosable: false,
      nzClosable: false,
      nzOnOk: ( ) => { // 保存
        callback();
      }
    });
  }
  /**
   * 模态框
   * info
   * title
   * msg
   * callback 回调
   */
  info(title , msg , callback): any {
    this.modalService.info({
      nzTitle: `<i>${title}</i>`,
      nzContent: `<b>${msg}</b>`,
      nzOnOk: callback
    });
  }
  /**
   * 模态框
   * success
   * title
   * msg
   */
  success(title , msg ): any {
    this.modalService.success({
      nzTitle: `<i>${title}</i>`,
      nzContent: `<b>${msg}</b>`,
    });
  }
  /**
   * 模态框
   * error
   * title
   * msg
   */
  error(title , msg ): any {
    this.modalService.error({
      nzTitle: `<i>${title}</i>`,
      nzContent: `<b>${msg}</b>`,
    });
  }
  /**
   * 模态框
   * warning
   * title
   * msg
   */
  warning(title , msg ): any {
    this.modalService.warning({
      nzTitle: `<i>${title}</i>`,
      nzContent: `<b>${msg}</b>`,
    });
  }

}
